var blue=[];
var red=[];
cc.Class({
    extends: cc.Component,
    
    properties: {
        mycolor:2,//初始点击次数统计
    },

    jiage:function(temp_rednum,temp_bluenum) {
        var temp_num_small=temp_rednum-6;
        var temp_jiagechengji=1;
        var temp_jiagechufa=1;
        var temp_jiage;
        if(temp_num_small<0){
            return 1;
        }else{
            for(var i=1;i<=temp_num_small;i++){
                temp_jiagechufa*=i;
            }
            for(var i=1;i<=temp_rednum;i++){
                temp_jiagechengji*=i;
            }
            temp_jiage=2*temp_bluenum*temp_jiagechengji/temp_jiagechufa/6/5/4/3/2/1;
            return temp_jiage;//返回价格
        }
    },
    arrnum:function(mynum) {
        function sequence(a,b){
            return a - b;
        };
        mynum=mynum.sort(sequence);
        var obj=[];
        var objindex=0;
        for (var i = 0, j = mynum.length; i < j; i++)
        {
            if(mynum[i]!=mynum[i+1]){
                obj[objindex]=mynum[i];
                objindex++;
            }
        };
        return obj;//返回数组
    },
    remove:function(mynum,myarr) {
        var index;
        function sequence(a,b){
            return a - b;
        };
        myarr=myarr.sort(sequence);
        for (var i = 0, j = myarr.length; i < j; i++)
        {
            if(myarr[i]==mynum){
                index=i;
            }
        };
        return index;//返回数组
    },
    btndown:function(){
        this.mycolor++;
        if(this.mycolor%2==0){
            this.node.color={a:255,b:255,g:255,r:255};//点击后变色(变白)
            if(this.node.parent.name=="red"){
                red.splice(this.remove(this.node.getChildByName("Label").getComponent(cc.Label).string,red),1);
            }else{
                blue.splice(this.remove(this.node.getChildByName("Label").getComponent(cc.Label).string,blue),1);
            };
            cc.find("Canvas/lbl_mynuml").getComponent(cc.Label).string=red+"+"+blue;
            cc.find("Canvas/lbl_jg").getComponent(cc.Label).string=this.jiage(red.length,blue.length);
            var lishixianshi3={};
            var lishixindex3=0;
            var lishixianshi31={};
            var lishixindex31=0;
            var lishixianshi4={};
            var lishixindex4=0;
            var lishixianshi41={};
            var lishixindex41=0;
            var lishixianshi5={};
            var lishixindex5=0;
            var lishixianshi51={};
            var lishixindex51=0;
            var lishixianshi6={};
            var lishixindex6=0;
            var lishixianshi61={};
            var lishixindex61=0;
            var lishired,lishibule;//重置统计的相同数量
            cc.loader.loadRes('ssqdate',function(err,ssqdate){
                if (err) {
                    cc.log(err);
                }
                for(var temp=0,k=ssqdate.json.shuju.length;temp<k;temp++){
                    var tongjired=0,tongjiblue=0;
                    lishired=ssqdate.json.shuju[temp].red;//赋值表格中的红球
                    lishibule=ssqdate.json.shuju[temp].blue;//赋值表格中的篮球
                    for(var i=0;i<red.length;i++){
                        for(var j=0;j<lishired.length;j++){
                            if(red[i]==lishired[j]){
                                tongjired+=1;//统计红球的相同数量
                            }
                        }
                    };
                    for(var i=0;i<blue.length;i++){
                        for(var j=0;j<lishibule.length;j++){
                            if(blue[i]==lishibule[j]){
                                tongjiblue+=1;//统计蓝球的相同数量
                            }
                        }
                    };
                    if(tongjired>=3){
                        switch(tongjired){
                            case 3:
                            if(tongjiblue==1){
                                //统计相同3+1的历史双色球组
                                lishixianshi31[lishixindex31]=lishired+"+"+lishibule;
                                lishixindex31++;
                            }else{
                                //统计相同3的历史双色球组
                                lishixianshi3[lishixindex3]=lishired+"+"+lishibule;
                                lishixindex3++;
                            }
                            break;
                            case 4:
                            if(tongjiblue==1){
                                //统计相同4+1的历史双色球组
                                lishixianshi41[lishixindex41]=lishired+"+"+lishibule;
                                lishixindex41++;
                            }else{
                                //统计相同4的历史双色球组
                                lishixianshi4[lishixindex4]=lishired+"+"+lishibule;
                                lishixindex4++;
                            }
                            break;
                            case 5:
                            if(tongjiblue==1){
                                //统计相同5+1的历史双色球组
                                lishixianshi51[lishixindex51]=lishired+"+"+lishibule;
                                lishixindex51++;
                            }else{
                                //统计相同5的历史双色球组
                                lishixianshi5[lishixindex5]=lishired+"+"+lishibule;
                                lishixindex4++;
                            }
                            break;
                            case 6:
                            if(tongjiblue==1){
                                //统计相同6+1的历史双色球组
                                lishixianshi61[lishixindex61]=lishired+"+"+lishibule;
                                lishixindex61++;
                            }else{
                                //统计相同6的历史双色球组
                                lishixianshi6[lishixindex6]=lishired+"+"+lishibule;
                                lishixindex6++;
                            }
                            break;
                        }
                    };
                }
                //输出统计到历史相同数
                cc.find("Canvas/lbllishi").getComponent(cc.Label).string="3:"+lishixindex3+"--3+1:"+lishixindex31+"--4:"+lishixindex4+"--4+1:"+lishixindex41+"--5:"+lishixindex5+"--5+1:"+lishixindex51+"--6:"+lishixindex6+"--6+1:"+lishixindex61;
            });
        }else{
            this.node.color={a:255,b:255,g:0,r:255};//点击后变色(变红)
            
            if(this.node.parent.name=="red"){
                red.push(this.node.getChildByName("Label").getComponent(cc.Label).string);
                red=this.arrnum(red);
            }else{
                blue.push(this.node.getChildByName("Label").getComponent(cc.Label).string);
                blue=this.arrnum(blue);
            };
            
            cc.find("Canvas/lbl_mynuml").getComponent(cc.Label).string=red+"+"+blue;
            cc.find("Canvas/lbl_jg").getComponent(cc.Label).string=this.jiage(red.length,blue.length);
            var lishixianshi3={};
            var lishixindex3=0;
            var lishixianshi31={};
            var lishixindex31=0;
            var lishixianshi4={};
            var lishixindex4=0;
            var lishixianshi41={};
            var lishixindex41=0;
            var lishixianshi5={};
            var lishixindex5=0;
            var lishixianshi51={};
            var lishixindex51=0;
            var lishixianshi6={};
            var lishixindex6=0;
            var lishixianshi61={};
            var lishixindex61=0;
            var lishired,lishibule;//重置统计的相同数量
            cc.loader.loadRes('ssqdate',function(err,ssqdate){
                if (err) {
                    cc.log(err);
                }
                for(var temp=0,k=ssqdate.json.shuju.length;temp<k;temp++){
                    var tongjired=0,tongjiblue=0;
                    lishired=ssqdate.json.shuju[temp].red;//赋值表格中的红球
                    lishibule=ssqdate.json.shuju[temp].blue;//赋值表格中的篮球
                    for(var i=0;i<red.length;i++){
                        for(var j=0;j<lishired.length;j++){
                            if(red[i]==lishired[j]){
                                tongjired+=1;//统计红球的相同数量
                            }
                        }
                    };
                    for(var i=0;i<blue.length;i++){
                        for(var j=0;j<lishibule.length;j++){
                            if(blue[i]==lishibule[j]){
                                tongjiblue+=1;//统计蓝球的相同数量
                            }
                        }
                    };
                    if(tongjired>=3){
                        switch(tongjired){
                            case 3:
                            if(tongjiblue==1){
                                //统计相同3+1的历史双色球组
                                lishixianshi31[lishixindex31]=lishired+"+"+lishibule;
                                lishixindex31++;
                            }else{
                                //统计相同3的历史双色球组
                                lishixianshi3[lishixindex3]=lishired+"+"+lishibule;
                                lishixindex3++;
                            }
                            break;
                            case 4:
                            if(tongjiblue==1){
                                //统计相同4+1的历史双色球组
                                lishixianshi41[lishixindex41]=lishired+"+"+lishibule;
                                lishixindex41++;
                            }else{
                                //统计相同4的历史双色球组
                                lishixianshi4[lishixindex4]=lishired+"+"+lishibule;
                                lishixindex4++;
                            }
                            break;
                            case 5:
                            if(tongjiblue==1){
                                //统计相同5+1的历史双色球组
                                lishixianshi51[lishixindex51]=lishired+"+"+lishibule;
                                lishixindex51++;
                            }else{
                                //统计相同5的历史双色球组
                                lishixianshi5[lishixindex5]=lishired+"+"+lishibule;
                                lishixindex4++;
                            }
                            break;
                            case 6:
                            if(tongjiblue>=1){
                                //统计相同6+1的历史双色球组
                                lishixianshi61[lishixindex61]=lishired+"+"+lishibule;
                                lishixindex61++;
                            }else{
                                //统计相同6的历史双色球组
                                lishixianshi6[lishixindex6]=lishired+"+"+lishibule;
                                lishixindex6++;
                            }
                            break;
                        }
                    };
                }
                //输出统计到历史相同数
                cc.find("Canvas/lbllishi").getComponent(cc.Label).string="3:"+lishixindex3+"--3+1:"+lishixindex31+"--4:"+lishixindex4+"--4+1:"+lishixindex41+"--5:"+lishixindex5+"--5+1:"+lishixindex51+"--6:"+lishixindex6+"--6+1:"+lishixindex61;
            });
        };
        if(this.mycolor==4){
            this.mycolor=2;//初始点击次数统计
        };
        

    },
    // onLoad () {},

    // start () {},

    // update (dt) {},
});
